# # -*- coding: utf-8 -*-
# from __future__ import unicode_literals
#
# from django.db import models
# from django.contrib.auth.models import User
# from jsonfield import JSONField
# from django.db.models.signals import post_save
# from rest_framework.authtoken.models import Token
#
#
# class WXAppToken(Token):
#     """
#     小程序微信登录Token
#     """
#     class Meta:
#         verbose_name = "WXAppToken"
#         verbose_name_plural = "WXAppTokens"
#
#     @classmethod
#     def update_token(cls, user):
#         token, res = WXAppToken.objects.update_or_create(user=user)
#         return token.key
#
#     @classmethod
#     def get_token(cls, user):
#         token = WXAppToken.objects.filter(user=user).first()
#         if token:
#             return token.key
#         else:
#             return WXAppToken.update_token(user)
#
#
# class UserProfile(models.Model):
#     user = models.OneToOneField(User, on_delete=True,  verbose_name="用户")
#     avatar = models.CharField("头像", max_length=300, blank=True, null=True)
#     nickname = models.CharField("昵称", max_length=16, default='', blank=True)
#     gender = models.IntegerField("性别", choices=((0, '女', ), (1, '男'),), default=0)
#     phone = models.CharField("电话", max_length=16, default='', blank=True)
#
#     class Meta:
#         verbose_name = u'用户资料'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return self.nickname
#
#     def __unicode__(self):
#         return self.nickname
#
#
# def create_user_profile(sender, instance, created, **kwargs):
#     if created:
#         profile = UserProfile()
#         profile.user = instance
#         profile.save()
#
#
# post_save.connect(create_user_profile, sender=User)
#
#
# class UserAuth(models.Model):
#     user = models.ForeignKey(User, on_delete=True, verbose_name="用户")
#     open_id = models.CharField("第三方登录标识", max_length=200)
#     types = (
#         ('weixin', 'weixin', ),
#     )
#     third_party_type = models.CharField("第三方登录类型", choices=types, max_length=10)
#     extras = JSONField(u'附加信息', default={})
#
#     class Meta:
#         verbose_name = u'用户第三方登录信息'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return self.user
#
#     @classmethod
#     def get_or_create(cls, openid, third_type):
#         user_auth = UserAuth.objects.filter(open_id=openid, third_party_type=third_type).first()
#         if user_auth is None:
#             user = User.objects.create()
#             user_auth = UserAuth.objects.create(user=user, open_id=openid, third_party_type=third_type)
#         return user_auth
